package com.bdqn.t382.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;


@Controller
@RequestMapping("/")
public class RegisterController {

    @GetMapping("/register")
    public ModelAndView showRegisterPage() {
        return new ModelAndView("register");
    }

    /**
     * 处理注册业务
     */
    @PostMapping("/register")
    public ModelAndView handleRegister() {
        // 这里可以添加具体的注册业务逻辑，比如保存用户信息到数据库等
        // 目前直接跳转回注册页面
        return new ModelAndView("register");
    }

    @PostMapping("/doRegister")
    public String handleRegister(@RequestParam("username") String username,
                                 @RequestParam("password") String password,
                                 Model model) {
        // 将用户输入的用户名和密码放入模型数据
        model.addAttribute("username", username);
        model.addAttribute("password", password);
        return "success";
    }
}
